package com.kun.portal.webframe.controller;

import com.kun.portal.webframe.po.ContractManagePo;
import com.kun.portal.webframe.po.GoodsInventoryPo;
import com.kun.portal.webframe.po.StockInPo;
import com.kun.portal.webframe.po.SupplierMgrPo;
import com.kun.portal.webframe.service.InventoryManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2018/7/2.
 */
@Controller
@RequestMapping({"/api/inventoryManagement"})
public class InventoryManagementController {
    @Autowired
    private InventoryManagementService inventoryManagementService;
    @InitBinder
    public void intDate(WebDataBinder dataBinder){
        dataBinder.addCustomFormatter(new DateFormatter("yyyy-MM-dd"));
    }
    @RequestMapping(
            value = {"/findGoods"},
            method = {RequestMethod.GET},
            produces = {"application/json"}
    )
    @ResponseBody
    public List<GoodsInventoryPo> findAllGoodsInventoryPo(){

        return inventoryManagementService.findAllGoodsInventoryPo();
           }
    @RequestMapping(
            value = {"/saveGoods"},
            method = {RequestMethod.POST},
            produces = {"application/json"}
    )
    @ResponseBody
    public void saveGoodsInventoryPo(@RequestBody GoodsInventoryPo goodsInventoryPo){
        inventoryManagementService.saveGoodsInventoryPo(goodsInventoryPo);
    }
    @RequestMapping(
            value = {"/saveStockIn"},
            method = {RequestMethod.POST},
            produces = {"application/json"}
    )
    @ResponseBody
    public void saveStockInPo(@RequestBody StockInPo stockInPo){
        inventoryManagementService.saveStockInPo(stockInPo);
    }
    @RequestMapping(
            value = {"/findAllStockInRecord"},
            method = {RequestMethod.POST},
            produces = {"application/json"}
    )
    @ResponseBody
    public List<StockInPo> findAllStockInRecord(){
        List<StockInPo> list = inventoryManagementService.findAllStockInRecord();
        return  inventoryManagementService.findAllStockInRecord();
    }
    @RequestMapping(
            value = {"/checkStockInRecord"},
            method = {RequestMethod.GET},
            produces = {"application/json"}
    )
    @ResponseBody
    public List<StockInPo> findStockInRecord(@RequestParam(required = false) String goodsCategory ,
                                              String goodsCode,
                                              Date stockDate,
                                              String supplier){
        return  inventoryManagementService.checkStockInRecordPo(goodsCategory,goodsCode,stockDate,supplier);

    }
    @RequestMapping(
            value = {"/findAllSupplierMgrPo"},
            method = {RequestMethod.GET},
            produces = {"application/json"}
    )
    @ResponseBody
    public List<SupplierMgrPo> findAllSupplierMgrPo(){
        return inventoryManagementService.findAllSupplierMgrPo();
    }
    @RequestMapping(
            value = {"/saveSupplierPo"},
            method = {RequestMethod.POST},
            produces = {"application/json"}
    )
    @ResponseBody
    public void saveSupplierPo(@RequestBody SupplierMgrPo supplierMgrPo){
      inventoryManagementService.saveSupplierPo(supplierMgrPo);
    }
    @RequestMapping(
            value = {"/checkSupplierMgrPo"},
            method = {RequestMethod.GET},
            produces = {"application/json"}
    )
    @ResponseBody
    public List<SupplierMgrPo> checkSupplierMgrPo(@RequestParam(required = false) String companyName ,
                                                  @RequestParam(required = false) String supplierAbbr){
        return  inventoryManagementService.checkSupplierMgrPo(companyName, supplierAbbr);
    }
    @RequestMapping(
            value = {"/delectSupplierMgrPo"},
            method = {RequestMethod.POST},
            produces = {"application/json"}
    )
    @ResponseBody
    public void deleteContractManagePo(@RequestBody SupplierMgrPo supplierMgrPo){
        inventoryManagementService.deleteSupplierMgrPo(supplierMgrPo);

    }



}
